from database.db_handler import MysqlHander

class MacroData:
    def __init__(self):
        self.db = MysqlHander("config.ini")
        pass

    def add_macro_data_temp(self, data_date, data_type, data_title, data_url, data_site):
        info_type = 0
        insert = "insert into macro_data_temp (Fdate, Ftype, Ftitle, Furl, Fsite, Fcreate_time, Fmodify_time) values "
        insert += "('" + data_date + "', " + str(data_type) + ",'" + data_title + "','" + data_url + "','" + data_site + "', now(), now());"
        
        print(insert)
        try:
            #pass
            self.db.execute_not_safe(insert)
        except Exception as e:
            print(str(e))
            pass

    def add_macro_data(self, data_date, data_type, data_title, data_url, data_site):
        print("add_macro_data")
        info_type = 0
        insert = "insert into macro_data (Fdate, Ftype, Ftitle, Furl, Fsite, Fcreate_time, Fmodify_time) values "
        insert += "('" + data_date + "', " + str(data_type) + ",'" + data_title + "','" + data_url + "','" + data_site + "', now(), now());"
        
        print(insert)
        try:
            #pass
            self.db.execute_not_safe(insert)
        except Exception as e:
            print(str(e))
            pass

    def query_macro_data(self, data_date):
        query = "select Fdate, Ftype, Ftitle, Furl, Fsite from macro_data where Fdate='" + data_date + "' order by Ftype;"
        
        print(query)
        return self.db.query_sql(query)
